{% extends "admin/change_form.html" %}
{% load i18n admin_urls static admin_modify admin_urls cms_admin cms_static %}

{% block title %}{% if add %}{% trans 'Add a page' %}{% else %}{% trans "Change a page" %}{% endif %}{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
    &rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
    &rsaquo; {% if has_change_permission %}<a href="{% url 'admin:cms_pagecontent_changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %}
    &rsaquo; {% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
</div>
{% endblock %}

{% block extrahead %}
<script src="{% static "admin/js/urlify.js" %}" type="text/javascript"></script>
<script src="{% static_with_version "cms/js/dist/bundle.admin.base.min.js" %}" type="text/javascript"></script>
<script src="{% static_with_version "cms/js/dist/bundle.admin.changeform.min.js" %}" type="text/javascript"></script>
{{ block.super }}
{% endblock %}

{% block content_title %}
    {% if title %}<h1>{{ title }}</h1>{% endif %}
    {% get_preview_url original as admin_url %}
    {% if not popup and not add %}
        <ul class="object-tools hide-in-modal">
            <li>
                <a href="{{ admin_url }}" target="_parent">{% trans "View on site" %}</a>
            </li>
        </ul>
    {% endif %}
{% endblock %}

{% block content %}
<div id="content-main">

{% block object-tools %}{% endblock %}

<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="?language={{ language }}{% if request.GET.parent_page %}&amp;parent_page={{ request.GET.parent_page }}{% endif %}{%if request.GET.source %}&amp;source={{ request.GET.source }}{% endif %}" method="post" id="{{ opts.model_name }}_form">
{% csrf_token %}
{% block form_top %}{% endblock %}

{% if show_language_tabs and not show_permissions %}
<div id="page_form_lang_tabs">
    {% for lang_code, lang_name in language_tabs %}
        <input type="button" onclick="CMS.API.changeLanguage('{% get_admin_url_for_language cms_page lang_code %}');"
            class="language_button {% if lang_code == language %}selected{% else %}{% if not lang_code in filled_languages %} notfilled{% endif %}{% endif %}"
            id="{{lang_code}}button" name="{{lang_code}}" value="{{lang_name}}" />
    {% endfor %}
    <div class="lang_tabs_line"></div>
</div>
{% endif %}

<div id="lang_tab_content">
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if save_on_top %}{% submit_row %}{% endif %}
{% if errors %}
<p class="errornote">
{% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
</p>
<ul class="errorlist">{% for error in adminform.form.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
{% endif %}

{% for fieldset in adminform %}
    {% include "admin/cms/page/includes/fieldset.html" %}
{% endfor %}

{% for inline_admin_formset in inline_admin_formsets %}
    {% include inline_admin_formset.opts.template %}
{% endfor %}

{% if show_permissions %}
    <div class="inline-group">
        <div class="tabular inline-related">
            <fieldset id="inherited_permissions" class="module aligned collapse">
              <h2>{% trans 'All permissions' %}</h2>
              <div class="loading" rel="../permissions/">{% trans 'Loading...' %}</div>
            </fieldset>
        </div>
    </div>
{% endif %}

{% block after_related_objects %}{% endblock %}

{% if add %}
    <div class="submit-row"{% if is_popup %} style="overflow: auto;"{% endif %}>
        <input type="submit" name="_save" class="default" value="{% trans 'Save' %}" {{ onclick_attrib }}/>
        <input type="submit" name="_continue" value="{% trans 'Save and continue editing' %}" {{ onclick_attrib }}/>
    </div>
{% else %}
    {% page_submit_row %}
{% endif %}
</div>
</form>
</div>

{% block admin_change_form_document_ready %}
{{ block.super }}
{% endblock %}

{# JavaScript for prepopulated fields #}
{% prepopulated_fields_js %}

{% endblock %}
